package com.lagou.homework.stage01.module04;

import java.io.File;

public class DelFiles {

    public static void delAllFile(File file) {
        System.out.println("Deleting file : "+file.getName());
        boolean b1 = file.delete();
        if(true==b1){
            return;
        }

        File[] filesArray = file.listFiles();
        for (File tf : filesArray) {
            System.out.println("Deleting file : "+tf.getName());
            b1 = tf.delete();
            if (false == b1) {
                if (tf.isDirectory()) {
                    delAllFile(tf);
                }
            }
        }
    }

    public static void main(String[] args) {
        String path = "d:/delFile";
        File file = new File(path);

        if(file.isDirectory()){
            File[] filesArray = file.listFiles();
            while(filesArray.length>0){
                delAllFile(file);
                filesArray = file.listFiles();
            }
        }else {
            delAllFile(file);
        }
    }
}
